package components
{
	import flash.utils.Dictionary;
	import flash.utils.describeType;
	
	public class ComponentData
	{
		public var id:int;
		
		public function ComponentData( base:Object )
		{
			this.readFrom( base );
		}
		
		private static var dataTypes:Dictionary = new Dictionary();
		
		public function readFrom( base:Object ):void
		{
			var myClass:Class = Object(this).constructor;
			
			var properties:Dictionary;
			if( !(properties=dataTypes[myClass]) )
			{
				properties = new Dictionary();
				dataTypes[myClass] = properties;
				var xml:XMLList = describeType( myClass )..variable;
				var len:int = xml.length();
				for( var i:int=0; i<len; ++i )
				{
					var name:String = String(xml.@name[i]);
					properties[name] = name;
				}
			}
			
			for( var key:String in properties )
			{
				if( base.hasOwnProperty(key) )
				{
					this[key] = base[key];
				}
			}
		}
	}
}